<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Stat_evaluasi extends CI_Controller 
{

    function __construct() 
	{
        parent::__construct();
        $this->load->library('flexigrid');
        $this->load->library('form_validation');
		$this->load->library('session');
        $this->load->helper('flexigrid');
        $this->load->helper(array('form', 'url'));
        $this->load->model('proyek_model');
		$this->load->model('evaluasi_model');   
    }

    //load Grid
    function index() 
	{
        if ($this->session->userdata('username') == NULL) 
		{
            redirect('login');
        } else 
		{
            $data['status'] = 'new';
            $data['failed'] = false;
            $data['aa'] = '';
			$data = str_replace("\'", "'", $data);
			$data['content'] = $this->load->view('stat_evaluasi', $data, true);
            $this->load->view('main', $data);
        }
    }

	
    function tampil() 
	{
        if ($this->session->userdata('username') == NULL) 
		{
            redirect('login');
        } else {
				
				$awal = $this->input->post('awal');
				$akhir = $this->input->post('akhir');
				
				if ($awal == Null || $akhir == Null) 
				{
				redirect('stat_surat');
				}
				else 
				{
												
					$sql = $this->db->query("SELECT COUNT(ID_PROYEK) AS proy FROM proyek WHERE TANGGAL_MULAI_PROYEK >= '".$awal."' AND TANGGAL_MULAI_PROYEK <= '".$akhir."'");
					
					foreach ($sql->result() as $rows) 
					{
						$proy = $rows->proy;
					}
				
					$sql2 = $this->db->query("SELECT COUNT(ID_EVALUASI) AS eval FROM evaluasi WHERE TANGGAL_MULAI_EVALUASI >= '".$awal."' AND TANGGAL_MULAI_EVALUASI <= '".$akhir."' AND AKTIF = 1");
				
					foreach ($sql2->result() as $rows) 
					{
						$eval = $rows->eval;
					}
					
					$sql3 = $this->db->query("SELECT COUNT(ID_EVALUASI) AS eval2 FROM evaluasi WHERE TANGGAL_MULAI_EVALUASI >= '".$awal."' AND TANGGAL_MULAI_EVALUASI <= '".$akhir."' AND AKTIF = 0");
				
					foreach ($sql3->result() as $rows) 
					{
						$eval2 = $rows->eval2;
					}
					
					$sql4 = $this->db->query("SELECT COUNT(ID_PROYEK) AS proy2 FROM proyek WHERE TANGGAL_MULAI_PROYEK >= '".$awal."' AND TANGGAL_MULAI_PROYEK <= '".$akhir."' AND STATUS_PROYEK = 'AKTIF'");
				
					foreach ($sql4->result() as $rows) 
					{
						$proy2 = $rows->proy2;
					}
						
					$data = array(
						'awal' => $awal,
						'akhir' => $akhir,
						'proy' => $proy,
						'eval' => $eval	,
						'eval2' => $eval2,
						'proy2' => $proy2
					);
				
					$data['content'] = $this->load->view('tampil_stat_evaluasi', $data, true);
					$this->load->view('main', $data);
				}
        }
    } 
   	
}
